package com.cn;

public abstract class AServer {
	public int id;
	public int port;
	public String ip;
	protected String name;
	
	public ICommandPool commandPool = new CommandPool();
	public MsgWorker msgWorker;
	
	protected AServer(String name) {
		this.name = name;
		addShutdownHook();
	}
	
	private void addShutdownHook(){
		final AServer bs = this;
		Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
			@Override
			public void run() {
				bs.stop();
				LogHelper.ERROR_LOGGER.error(bs.name + " Stop!!");
			}
		}));
	}
	
	public void start(){
		msgWorker.start();
	}
	
	public void stop(){
		msgWorker.shutdown();
	}
	
	public abstract void init();
	
}

